/**
 * 
 */
package Graphique;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;

/**
 * @author tangi
 *
 */
public class ConnectionFrame {
	
	private Display display;
	private Shell shell;
	private CompositeConnexion connectComposite;
	
	public ConnectionFrame(){
		
		initShell();	
		initComposite();
		shell.pack();		
		
		//Petite opération pour placer le shell au milieu
		Monitor primary = display.getPrimaryMonitor ();
		Rectangle bounds = primary.getBounds ();
		Rectangle rect = shell.getBounds ();
		int x = bounds.x + (bounds.width - rect.width) / 2;
		int y = bounds.y + (bounds.height - rect.height) / 2;
		shell.setLocation (x, y);
		
		// Set up the event loop.
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				// If no more entries in event queue
				display.sleep();
			}
		}
	
		display.dispose();
	
		// If the connection is still running 
		// we open the Movie Pointer
		if (connectComposite.connecte()){
			new MainFrame(connectComposite.getConnection());
		}
	}

	private void initShell() {
		display = new Display();
		shell = new Shell(display, SWT.CLOSE | SWT.CENTER);
		shell.setLayout(new FormLayout());
		shell.setText("Fenetre de Connexion");
		shell.open();		
	}
	
	private void initComposite(){
		connectComposite = new CompositeConnexion(shell, SWT.NONE);
	}
	

}
